/**
 * 定义状态信息模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.ws.wsclcManager.wsclcInfo.wwtpAttentionManager', ['water.entity.wwtpAttention']);
	module.controller('wwtpAttentionManagerController',function($wdp,$rootScope,$scope,$wwtpAttentionService){
		/**
		 * 查询条件
		 */
		$scope.queryObject={};
		/**
		 * 查询数据
		 */
		$scope.wwtpAttentionData={};
		/**
		 * 新建数据
		 */
		$scope.dataWwtpAttentionCreate = {};
		/**
		 * 年份数据
		 */
		$scope.yearList=[];
		/**
		 * 新建按钮点击
		 */
		$scope.onCreateClick=function(){
			$scope.dataWwtpAttentionCreate = {};
			$scope.createDialog.open();
		};
		/**
		 * 新建提交
		 */
		$scope.onSubmitCreateClick = function(data){
			data.WWTP_EXP_NO=$scope.queryObject.WWTP_ID;
			if((data.START_DATE.split('-')[0]!=data.NAME)||(data.END_DATE.split('-')[0]!=data.NAME)){
				$.messager.alert("选择日期与年份不符！","选择日期与年份不符！",'info');
				return;
			}
			
			$wwtpAttentionService.createModel(data).then(function(){
				$scope._getwwtpAttentionDataList();
				$.messager.alert("保存成功","保存成功",'info');
				$scope.createDialog.close();
			});
		};
		/**
		 * 新建取消按钮
		 */
		$scope.onSubmitCancleClick = function(){
				$scope.createDialog.close();
		};
		
		/**
		 * 删除
		 */
		$scope.onSubmitDeleteClick=function(data){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$wwtpAttentionService.deleteModel(data.GUID).then(function(){
						$scope._getwwtpAttentionDataList();
						$.messager.alert("删除成功","删除成功",'info');
					});			
				}
			});
		};
		/**
		 * 监控污水处理厂id变化
		 */
		if($wdp.viewValue.wwtpDetailParmWatch){
			$wdp.viewValue.wwtpDetailParmWatch();
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			$scope.queryObject.WWTP_ID = $wdp.viewValue.wwtpDetailParm.WWTPID;
			$scope._getwwtpAttentionDataList();
        },true);
		/**
		 * 获取状态数据
		 */
		$scope._getwwtpAttentionDataList=function(){
			$wwtpAttentionService.getList($scope.queryObject).then(function(d){
				if(d.data.length < 1){
					$scope.wwtpAttentionData = {};
					return;
				}
				$scope.wwtpAttentionData=d.data;
			});
		};
		/**
		 * 初始化时间数据
		 */
		function _init(){
			$scope.yearList=[];
			var nowDate = new Date();
			var y=nowDate.getFullYear();
			for(var i=0;i<6;i++){
				var obj=new Object();
				obj.k=y-i+"";
				obj.v=y-i+"";
				$scope.yearList.push(obj);
			}; 
		};
		_init();
	});
}(window, angular));